package com.jqr.activity.school;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.jqr.activity.school.http.JqrService;
import com.jqr.activity.school.http.ResponseTransformer;
import com.jqr.activity.school.models.Article;
import com.jqr.activity.school.models.ArticleCats;
import com.jqr.activity.school.models.jsontobean.JsonBean;

import java.util.List;

import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@AndroidEntryPoint
public class MainActivity extends AppCompatActivity {
    Button button;
    @Inject
    JqrService jqrService;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("CheckResult")
            @Override
            public void onClick(View v) {
//               Call<JsonListBean<Article>> call=jqrService.getAllArticles();
//               call.enqueue(new Callback<JsonListBean<Article>>() {
//                   @Override
//                   public void onResponse(Call<JsonListBean<Article>> call, Response<JsonListBean<Article>> response) {
//                       JsonListBean<Article> result=response.body();
//
//
//
//                   }
//
//                   @Override
//                   public void onFailure(Call<JsonListBean<Article>> call, Throwable t) {
//
//                   }
//               });



//                call.enqueue(new Callback<JsonBean<Article>>() {
//                    @Override
//                    public void onResponse(Call<JsonBean<Article>> call, Response<JsonBean<Article>> response) {
//                        JsonBean<Article> jsonBean=response.body();
//
//                        System.out.println(jsonBean.getData().getData().getTitle());
//                    }
//
//                    @Override
//                    public void onFailure(Call<JsonBean<Article>> call, Throwable t) {
//
//                    }
//                });
                //使用RxJava
                jqrService.getArticleById(1)
                        .compose(ResponseTransformer.obtain())
                        .subscribe(new Consumer<Article>() {
                            @Override
                            public void accept(Article article) throws Throwable {
                                System.out.println(article.toString());
                            }
                        });
//                        .subscribe(
//                        new Consumer<JsonBean<Article>>() {
//                            @Override
//                            public void accept(JsonBean<Article> articleJsonBean) throws Throwable {
//                                System.out.println(articleJsonBean.getData().getData().getTitle());
//                            }
//                        },
//
//                        new Consumer<Throwable>() {
//                            @Override
//                            public void accept(Throwable throwable) throws Throwable {
//
//                            }
//                        }
//
//                );
            }
        });


    }
}